//
//  WHMyCenterVC.m
//  WHEasyBizLink
//
//  Created by shengmeng chen on 2024/11/23.
//

typedef NS_OPTIONS(NSUInteger, WHMeIndexPathRow)
{
    WHMeIndexPathRowPerson     = 0,    // 我的个人信息
    WHMeIndexPathRowRegiser    = 1,    // 注册用户
    WHMeIndexPathRowSysitem    = 2,    // 服务平台
    WHMeIndexPathRowVersion    = 3,    // 更新版本
    WHMeIndexPathRowExit       = 4,   // 退出
};

NSString * const kWHAlertTitle         = @"温馨提示";
NSString * const kWHAlertContent       = @"确定要退出当前账号？";
NSString * const kWHAlertSure          = @"确定";
NSString * const kWHAlertCancel        = @"取消";

#import "WHMyCenterVC.h"
#import "WHMeModel.h"
#import "WHMeTableView.h"
#import "WHTdsSelectVC.h"
#import "WHLoginViewController.h"
#import "WHUpdateVersionViewController.h"

@interface WHMyCenterVC ()<MeTableViewDelegate,UIAlertViewDelegate,UIActionSheetDelegate>
@property(nonatomic,strong) WHMeTableView*tableView;
@end

@implementation WHMyCenterVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[UIColor whiteColor];
    self.title = @"我的";
    
    self.view.backgroundColor =[UIColor whiteColor];
    [self.view addSubview:self.tableView];
    NSMutableArray *arr = [WHMeModel getWHMeModels];
//    NSInteger cell = ceil((ScreenH - navHeight1 - ScreenH/4 - 60*arr.count)/60);
//    for (int i = 0; i<cell; i++) {
//        [arr addObject:[WHMeModel new]];
//    }
    self.tableView.models = arr;
    self.view.layer.contents = (__bridge id _Nullable)([UIImage imageNamed:@"enterprise_bg"].CGImage);
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.subviews.firstObject.alpha = 0;
}

#pragma mark - delegate
-(void)meTableViewChickIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==WHMeIndexPathRowPerson)
    {
//        WHPersonalInfomationVC*vc = [WHPersonalInfomationVC new];
//        vc.wHMeModel =self.tableView.models.firstObject;
//        [self pushViewController:vc];
    }
   else if (indexPath.row==WHMeIndexPathRowRegiser)
    {
        WHLoginViewController*vc = [WHLoginViewController new];
        [self pushViewController:vc];
    }
    else if (indexPath.row==WHMeIndexPathRowSysitem)
    {
        WHTdsSelectVC*vc =[[WHTdsSelectVC alloc]init];
       [self pushViewController:vc];
    }
    else if (indexPath.row==WHMeIndexPathRowVersion)
    {
        WHUpdateVersionViewController*vc=[WHUpdateVersionViewController new];
        [self  pushViewController:vc];
    }
    else if (indexPath.row ==WHMeIndexPathRowExit)
    {
        [self userLoginOutClick];
    }
}
-(void)pushViewController:(UIViewController*)vc
{
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//退出登陆
-(void)userLoginOutClick
{
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:kWHAlertTitle message:kWHAlertContent preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction *alertA = [UIAlertAction actionWithTitle:kWHAlertSure style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        //主线更新界面
        dispatch_async(dispatch_get_main_queue(), ^{
         [self exitApplication];
        });
    }];
    UIAlertAction *alertB = [UIAlertAction actionWithTitle:kWHAlertCancel style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
    }];
    [alertC addAction:alertB];
    [alertC addAction:alertA];
    [self presentViewController:alertC animated:YES completion:nil];
}

//4、退出app程序（不推荐使用，这种方式会让用户觉得app闪退）
-(void)exitApplication
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [UIView animateWithDuration:1.0f animations:^{
        window.alpha = 0;
        window.frame = CGRectMake(window.bounds.size.width/2, window.bounds.size.height/2, 0, 0);
    } completion:^(BOOL finished) {
        exit(0);
    }];
}

-(WHMeTableView *)tableView
{
    if (!_tableView)
    {
        _tableView=[WHMeTableView new];
        _tableView.frame  = CGRectMake(20,navHeight1,ScreenW-40,ScreenH-navHeight1);
        //去掉多余Cell
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        _tableView.meTableViewDelegate = self;
//        _tableView.bounces = NO;//去掉回弹
        _tableView.showsVerticalScrollIndicator = NO;//隐藏滚动条
    }
    return _tableView;
}
@end
